﻿using DIM_Tool;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Sunny.UI;
using System;
using System.IO;
using System.Threading;

namespace DIM_Server
{
    public partial class Index : UIForm
    {
        public Index()
        {
            InitializeComponent();
        }
        private void Index_Load(object sender, EventArgs e)
        {
            Initpro();
            CheckForIllegalCrossThreadCalls = false;
        }
        /// <summary>
        /// 初始化
        /// </summary>
        private void Initpro()
        {
           
        }
        /// <summary>
        /// 数据库初始化
        /// </summary>
        private void DATA_INIT()
        {
            try
            {
                string[] str = new string[4];

                string Body = File.ReadAllText("database_config.json", System.Text.Encoding.UTF8);

                JObject TEMP = (JObject)JsonConvert.DeserializeObject(Body);

                str[0] = TEMP["服务器IP"].ToString();

                str[1] = TEMP["数据库"].ToString();

                str[2] = TEMP["用户"].ToString();

                str[3] = TEMP["密码"].ToString();

                Public_Class.Database_Sql = new Database_sql(str);

                Tuple<bool, string> tuple = Public_Class.Database_Sql.Connect_sql();

                if (tuple.Item1)
                {
                    toolStripLabel_sql.Text = "已连接";
                }
                else
                {
                    toolStripLabel_sql.Text = "未连接";
                }
            }
            catch (Exception ex)
            {
                UIMessageTip.ShowError(ex.Message);
            }
        }

        private void uiButton1_Click(object sender, EventArgs e)
        {
            Thread thread = new Thread(DATA_INIT);
            thread.Start();
        }
    }
}
